const mixin = {
  data() {
    return {
      baseSize: null,
      originData: null,
      myChart: null,
      dataUrl: null
    }
  },
  computed: {
    option() {
      return {}
    }
  },
  methods: {
    async getData(url) {
      this.dataUrl = url || this.dataUrl
      const { data: ret } = await this.$axios.get(this.dataUrl);
      this.originData = ret;
    },
    init(containerID, dataUrl) {
      let element = document.getElementById(containerID)
      console.log('zujian:' + this.$curTheme);

      this.myChart = this.$echarts.init(element, this.$curTheme ? '' : 'chalk')
      this.baseSize = element.offsetWidth / 20
      window.addEventListener('resize', () => {
        this.baseSize = element.offsetWidth / 24
        this.myChart.resize();
        this.updateChart()
      })
      this.dataUrl = dataUrl
    },
    async renderChart() {
      await this.getData()
      this.dealData()
      this.myChart.setOption(this.option)
    },
    dealData() {
      // 处理原始数据,配置option中的数据项
      console.log("mixin dealData");
    },
    updateChart(option) {
      option = option || this.option
      this.myChart.setOption(option)
    }
  },
}
export default mixin